<?php 
	$url_teacher_add = $this->url(array('module'=>'teacher','controller'=>'index','action'=>'add-teacher'));
?>
<style>
<!--
tr td.tds{
	width: 15%; padding:10px 20px;
}
tr td.tdtext{
	width: 35%;
}
-->
</style>
<form action="<?php echo $url_teacher_add;?>" method="post" id="frm" enctype="multipart/form-data">
      <div id="page-wrapper">
        <div class="row">
        <div class="panel-heading" style=" width: 80%; margin:0 auto;">    	  
        	 <h3 style="color:#00F">Create User Teacher </h3>
          <button name="save_new" value="save_new" class="btn btn-small btn-primary">
			<b><i class="fa fa-plus"></i></b> &nbsp;Save New 
		  </button>
		  <button name="save_colse" value="save_colse" class="btn btn-small btn-primary">
		  <b><i class="icon-check"></i></b> &nbsp;Save Colse	
		  </button>
		  <a href="<?php ?>">
		  <button type="button" name="cancel" value="cancel" class="btn btn-small btn-warning">
			  <b><i class="fa fa-times"></i></b> &nbsp;Cancel					 
		  </button>
		  </a>
		  <div style="width: 20%; float: right;"><?php echo $this->frmteacher->getElement("id_code");?></div><div style="float: right; margin: 5px 0 30px 0;">ID Code Teacher : </div>
        </div>        
        <table border="0" cellpadding="5" width="90%" style="margin:0 auto;">
        	<tr>
            	<td class="tds">User Name Teacher :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("teacher_name");?></td>
                <td class="tds">Gender :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("gender");?></td>
            </tr>
            <tr>
            	<td class="tds">Email :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("email");?></td>
                <td class="tds">Phone Number :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("tel");?></td>
            </tr>
            <tr>
            	<td class="tds">Address :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("address");?></td>
            	<td class="tds">Place of Birth :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("pob");?></td>
            </tr>
            <tr>
            	<td class="tds">Date fo Birth :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("dob");?></td>
            	<td class="tds">Education Level :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("education_level");?></td>
            </tr>
             <tr>
            	<td class="tds">Finish From :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("finish_from");?></td>
            	<td class="tds" >Year :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("year");?></td>
            </tr>
            <tr>
            	<td class="tds"> Chose Department :</td>
                <td class="tdtext"> 
                	<div class="style-form" style="text-align: center;">
						<div class="" style="padding:10px 5px;"> 
							<div class="" style="height: 35px; text-align: left;">
								<div class="blocksearch">
									<select style="height: 35px;" id="department_id" name="department_id" Onchange="getdptOrder()"  class="chosen-select form-control"  style="width:100% ;margin:0 auto;" tabindex="4">
										<?php echo $this->department; ?>
									</select>
								</div>
							</div>
						</div>
					</div>
                </td>
            	<td class="tds">Status :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("status");?></td>
            </tr>
             <tr>
            	<td class="tds">Subject :</td>
                <td class="tdtext"> 
	                <div class="style-form" style="text-align: center;">
						<div class="" style="padding:10px 5px;"> 
							<div class="" style="height: 35px; text-align: left;">
								<div class="blocksearch">
									<select style="height: 35px;" id="add_subject" name="add_subject" Onchange="getsubjectOrder()"  class="chosen-select form-control"  style="width:100% ;margin:0 auto;" tabindex="4">
										<?php //echo $this->subjects; ?>
									</select>
								</div>
							</div>
						</div>
					</div>
					<div id="tabs" class="tabs-bottom">		
						<div id="tabs-1">
							<div class="head_form">
							<?php echo "Table Subject";?>
							</div>
					   	<div class="contain_form">
					   		<div class="">
					   			<table class="" id="table_order">
									<tr height="33px">
										<td class="sub-tdheader"><?php echo ("Delete");?></td>
										<td class="sub-tdheader"><?php echo ("ID");?></td>
										<td class="sub-tdheader"><?php echo ("Subject Name");?></td>
										<input type="hidden" id="identity" name="identity" />
									</tr>
								</table>
							</div>      
					   	</div><!-- end of .contain_table -->
					 </div><!-- tab 1 -->				
					</div><!-- end main tab -->	
                <?php // echo $this->frmteacher->getElement("subject");?>
                </td>
            	<td class="tds">Skill :</td>
                <td class="tdtext"> <?php //echo $this->frmteacher->getElement("skill");?>
                <div class="style-form" style="text-align: center;">
						<div class="" style="padding:10px 5px;"> 
							<div class="" style="height: 35px; text-align: left;">
								<div class="blocksearch">
									<select style="height: 35px;" id="add_skill" name="add_skill" Onchange="getskill()"  class="chosen-select form-control"  style="width:100% ;margin:0 auto;" tabindex="4">
										<?php echo $this->skills; ?>
									</select>
								</div>
							</div>
						</div>
					</div>
					<div id="tabs" class="tabs-bottom">		
						<div id="tabs-1">
							<div class="head_form">
							<?php echo "Table Skill";?>
							</div>
					   	<div class="contain_form">
					   		<div class="">
					   			<table class="" id="table_orders">
									<tr height="33px">
										<td class="sub-tdheader"><?php echo ("Delete");?></td>
										<td class="sub-tdheader"><?php echo ("ID");?></td>
										<td class="sub-tdheader"><?php echo ("Skill Name");?></td>
									</tr>
									<input type="hidden" id="identitysk" name="identitysk" />
								</table>
							</div>      
					   	</div><!-- end of .contain_table -->
					 </div><!-- tab 1 -->				
					</div><!-- end main tab -->	
                </td>
            </tr>
            <tr>            	               
            	<td class="tds">Description :</td>
                <td class="tdtext"> <?php echo $this->frmteacher->getElement("description");?></td>
                <td class="tds">Photo :</td>
                <td class="tdtext" style="text-align: center;">
                	<?php if($this->frmteacher->getElement("photo") !=null){ ?>
                		<img width="160px" title="Porfile" src="<?php echo $this->baseUrl();?>/images/images_profile.jpg" />
                	<?php } else {?>
                		<img width="160px" title="Porfile" src="<?php echo $this->baseUrl();?>/images/<?php echo $this->frmteacher->getElement('photo');?>"/>
                	<?php }?>
                	<?php echo $this->frmteacher->getElement("photo");?>
                </td>
                
            </tr>
        </table>
        
        </div><!-- /#page-row -->
      </div><!-- /#page-wrapper -->
</form>
 <!-- end new Skill -->
<div id="overlay-location" class="web_dialog_overlay"></div>
		<?php $form_skill = $this->add_frmskill; ?>
		<div id="dialog-location" class="web_dialog">
		<form id="frm-skill">
			<div class="web_dialog_title" align="center"><?php echo "Add New Skill"?>
				<a href="#" id="btnCloseLocation" class="cancelDailog"></a>
			</div>
			<table style="width: 100%; margin:0 auto;" cellpadding="3" cellspacing="0">
				
				<tr>
					<td>Skill Name</td>
					<td><?php echo $form_skill->getElement("skill");?></td>
				</tr>
				<tr>
					<td>Status </td>
					<td><?php echo $form_skill->getElement("status");?></td>
				</tr>
				<tr>
					<td colspan="2" style="text-align: center;">
						<input id="btn_add" Onclick="addNewLocation()" type="button" value="Add Skill" />
						<input id="btncancel_location" class="cancelDailog" type="button" value="Cancel" />
					</td>
					<td colspan="2"></td>
				</tr>
	       </table>
	     </form>
 </div>
<script>
//$("#add_dpt").chosen();
//$("#add_subject").chosen();
//$("#add_skill").chosen();
var index5 = 0;num=0;
var option5 = '<?php echo $this->subjects;?>';
var option5_skill = '<?php echo $this->skills;?>';
var baseUrl = '<?php echo BASE_URL; ?>';
var template = '';
var value = '';
function addRow(item_id) {
	index5++;
	for(i=1; i<index5; i++){
		new_subject=parseInt(item_id);
		subjects = parseInt($("#item_id_"+i).val());
		if(new_subject==subjects){
			if((free.checked==control.checked)){
				getSubject(i);
				return false;
			}
			else{
			}
		}
	}
	template='<tr id="row_order_'+index5+'" style="height:33px;" >';
	num=num+1;
	template+='<td class="quater-input"><img onClick="deleteRecord('+index5+')" src="<?php echo BASE_URL; ?>/images/icon/delete.gif" /></td>';
	template+='<td class="quater-input" width="3%">'+num+'<input type="hidden" value="" name="item_id_'+index5+'" id="item_id_'+index5+'" /></td>';
	template+='<td class="quater-input" width="100%"><select disabled="disabled"  class="form-control validate[required]" onChange="getSubject('+index5 +');" id="subject_id_'+index5+'" name="subject_id_'+index5+'">'+option5+'</select></td>';
	template+="</tr>";
	$('#table_order').append(template);
	if($('#identity').val()!="") {
		var identity = $('#identity').val();
		$('#identity').val(identity+','+index5);
	} else {$('#identity').val(index5);};
	$("#item_id_"+index5).val(item_id);
	$("#subject_id_"+index5).val(item_id);
	$("#orderFrm").validationEngine();
	ids=$("#subject_id_"+index5).val();
}
var record_index= 1;
function getSubject(index){
	subject_id = $("#subject_id_"+ index).val();
	subject_id = $("#subject_id_"+ index).val();
	checksubjectQuantity(subject_id);
	if(subject_id==-1){
		     record_index = index;
			 ShowDialog(true);
	}
	else{
		if(subject_id==null || subject_id==''){
			alert('Please Select Subject ');
			return false;
	    }
		
	}
}
function deleteRecord(index) {
	var identity = $('#identity').val();
	var arrays = identity.split(',');
	for(var i=0;i<arrays.length;i++) {
		if(arrays[i] == index) arrays.splice(i,1);
	}
	var strings = arrays.join(',');
	$('#identity').val(strings);
	$("#row_order_"+index).remove();

	// subject_name price
	netsubject_name();
	dosubject_name();
}
function deleteRecords(index) {
	var identity = $('#identitysk').val();
	var arrays = identity.split(',');
	for(var i=0;i<arrays.length;i++) {
		if(arrays[i] == index) arrays.splice(i,1);
	}
	var strings = arrays.join(',');
	$('#identitysk').val(strings);
	$("#row_order_"+index).remove();

	// subject_name price
	netskill_name();
	doskill_name();
}
function getsubjectOrder(){
	subject_ids=$("#add_subject").val();
	$('#add_subject').val('').trigger("liszt:updated");
	if(subject_ids==-1){
		return false;
	}
	addRow(subject_ids);
}
function getskill(){
	skill_id = $("#add_skill").val();
	$('#add_skill').val('').trigger("liszt:updated");
	if(skill_id == -1){
		addPupupskill(true);
	}
	addRowskill(skill_id);
}
function addRowskill(itemsk_id) {
	index5++;
	for(i=1; i<index5; i++){
		new_skill = parseInt(itemsk_id);
		skill = parseInt($("#skill_id_"+i).val());
		if(new_skill==skill){
			if((free.checked==control.checked)){
				getSubject(i);
				return false;
			}
			else{
			}
		}
	}
	template='<tr id="row_order_'+index5+'" style="height:33px;" >';
	num=num+1;
	template+='<td class="quater-input"><img onClick="deleteRecords('+index5+')" src="<?php echo BASE_URL; ?>/images/icon/delete.gif" /></td>';
	template+='<td class="quater-input" width="3%">'+num+'<input type="hidden" value="" name="itemsk_id_'+index5+'" id="itemsk_id_'+index5+'" /></td>';
	template+='<td class="quater-input" width="100%"><select disabled="disabled"  class="form-control validate[required]" onChange="getskills('+index5 +');" id="skill_id_'+index5+'" name="skill_id_'+index5+'">'+option5_skill+'</select></td>';
	template+="</tr>";
	$('#table_orders').append(template);
	if($('#identitysk').val()!="") {
		var identitysk = $('#identitysk').val();
		$('#identitysk').val(identitysk+','+index5);
	} else {$('#identitysk').val(index5);};
	$("#itemsk_id_"+index5).val(itemsk_id);
	$("#skill_id_"+index5).val(itemsk_id);
	$("#orderFrm").validationEngine();
	ids=$("#skill_id_"+index5).val();
}
var record_indexs= 1;
function getskills(indexs){
}
<?php $url_add_skill =  $this->url(array('module'=>'teacher','controller'=>'index','action'=>'add-new-skill')); ?>
function addPupupskill(){
	alert("faile insert ok");
}
<?php $url_dpt_filter =  $this->url(array('module'=>'teacher','controller'=>'index','action'=>'get-dpt-filter')); ?>
function getdptOrder(){
	//alert(12345);
	var dpt_id = $('#department_id').val();
	alert(dpt_id);
		$.ajax({
			url:"<?php echo $url_dpt_filter;?>",
			type:"post",
			data:{'dpt_id':dpt_id},
			success: function(data){
				items = $.parseJSON(data);
// 				alert(items);
// 				alert(items.length);
				if(items!=null){
					$('#add_subject').empty();
					 $('#add_subject').val('').trigger("liszt:updated");
					 $('#add_subject').append($("<option></option>").attr("value","").text("Please Select Subject"));
					 for (var index = 1 ; index <= items.length; index++) {
							$('#add_subject').append($("<option></option>").attr("value",items[index-1]['subject_id']).text(items[index-1]['subject_name'])); 
							$("select#add_subject").find("option#add_subject[index-1]['subject_id']").attr("selected", true);
					 }               
					$('#add_subject').val('').trigger("liszt:updated");
				}else{
					 $('#add_subject').empty();
					 $('#add_subject').val('').trigger("liszt:updated");
					 $('#add_subject').append($("<option></option>").attr("value","").text("No Result!"));
					//$('#add_subject').val('').trigger("liszt:updated");
				}
			},
			error:function(){
			}
		});
	}
</script>